home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / com32 / lib / onexit.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-11-10  |  643 b   |  40 lines

  1. /*
  2.  * onexit.c
  3.  */
  4.  
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include "atexit.h"
  8.  
  9. extern __noreturn (*__exit_handler)(int);
  10. static struct atexit *__atexit_list;
  11.  
  12. static __noreturn on_exit_exit(int rv)
  13. {
  14.   struct atexit *ap;
  15.   
  16.   for ( ap = __atexit_list ; ap ; ap = ap->next ) {
  17.     ap->fctn(rv, ap->arg);    /* This assumes extra args are harmless */
  18.   }
  19.   
  20.   _exit(rv);
  21. }
  22.  
  23. int on_exit(void (*fctn)(int, void *), void *arg)
  24. {
  25.   struct atexit *as = malloc(sizeof(struct atexit));
  26.  
  27.   if ( !as )
  28.     return -1;
  29.  
  30.   as->fctn = fctn;
  31.   as->arg  = arg;
  32.  
  33.   as->next = __atexit_list;
  34.   __atexit_list = as;
  35.  
  36.   __exit_handler = on_exit_exit;
  37.  
  38.   return 0;
  39. }
  40.